﻿using Library.Classes;
using System.ComponentModel;
using System.Data;
using System.Windows;

namespace Library.Windows
{
    /// <summary>
    /// Логика взаимодействия для Books.xaml
    /// </summary>
    public partial class Books : Window
    {
        private List<Author> authorList = new List<Author>();
        public Books()
        {
            InitializeComponent();
            authorList = LoadAuthors();
            cbAuthors.DataContext = authorList;
            cbAuthors.Items.SortDescriptions.Add(new SortDescription("LastName", ListSortDirection.Ascending));
            
        }

        private List<Author> LoadAuthors()
        {
            DataTable dt = SendToServer.GetAuthor();
            List<Author> authors = new List<Author>();
            if (dt.Rows.Count != 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    Author author = new Author(
                        id: Convert.ToInt32(row[0]),
                        lastName: Convert.ToString(row[1]),
                        firstName: Convert.ToString(row[2]),
                        patronymic: Convert.ToString(row[3])
                        );
                    authors.Add( author );
                }
            }
            return authors;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }
    }
}
